package net.jgrm.order.feign;

import net.jgrm.order.feign.fallback.ProductFeignFallback;
import net.jgrm.product.dto.ProductDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 商品服务Feign客户端
 */
@FeignClient(value = "product-service", fallback = ProductFeignFallback.class)
public interface ProductFeignClient {

    /**
     * 根据ID查询商品
     */
    @GetMapping("/api/products/{id}")
    ProductDTO getProductById(@PathVariable("id") Long id);

    /**
     * 扣减库存
     */
    @PostMapping("/api/products/{id}/decrease-stock")
    boolean decreaseStock(
            @PathVariable("id") Long id,
            @RequestParam("quantity") Integer quantity);
}
